#coding=utf-8

import stockdb.misc as misc
import strategy.basic as basic

def chaodie_filter(td, n=20):
    pre = td.pre
    if not pre: return False
    
    lowest = pre.lowest(n)
    if not lowest:return False
    
    if td.close <= lowest:
        return True
        
    return False

if __name__ == '__main__':
    date = '2008-04-03'
    #date = today
    print date
    
    tds = misc.find_tds_on(date)
    tf = basic.TDFilter(tds)

    tds = tf.filter_by(basic.st_filter).\
             filter_by(chaodie_filter, 20).\
             filter_by(basic.tdattr_filter, 'close', 5, 35).\
             filter_by(basic.tdattr_filter, 'change', 0, 10).\
             all()
             
    cs = []
    for t in tds:
        s = t.fins
        print s.code, s.name
